Objective and Methodology

Explore the change in the Gender Inequality Index (GII) by country, between 2010 and 2019.

We used the Human Development Report dataset and create the value of the difference between 2019 and 2010. Then we merge it with world boundaries.The maps below shows the variation in GII between 2010 and 2019.

Process

First, we load all the necessary packages

Import the CSV

Then, we read the .csv file, select the data we need and calculate the difference between years 2019 and 2010.

df_gii<- read.csv("HDR25_Composite_indices_complete_time_series.csv", 
                  fileEncoding = "latin1",
                  na.strings = "n/a") %>%
  select(country, iso3, gii_2010, gii_2019) %>%
  mutate(diff2019_10 = gii_2010 - gii_2019)
head(df_gii)
##               country iso3 gii_2010 gii_2019 diff2019_10
## 1         Afghanistan  AFG    0.704    0.676       0.028
## 2             Albania  ALB    0.192    0.131       0.061
## 3             Algeria  DZA    0.508    0.385       0.123
## 4             Andorra  AND       NA       NA          NA
## 5              Angola  AGO    0.556    0.536       0.020
## 6 Antigua and Barbuda  ATG       NA       NA          NA

Import the GPKG

Ckeck the gpkg layers and the CRS

st_layers(here("World_Countries_(Generalized)_8414823838130214587.gpkg"))
## Driver: GPKG 
## Available layers:
##                    layer_name geometry_type features fields
## 1 World_Countries_Generalized Multi Polygon      251      4
##                   crs_name
## 1 WGS 84 / Pseudo-Mercator

Load the gpkg

worldmap <- st_read(here("World_Countries_(Generalized)_8414823838130214587.gpkg"))%>%
  clean_names()
## Reading layer `World_Countries_Generalized' from data source 
##   `C:\Users\nadia\Documents\CASA\02_Geographic_Information_Systems\GISrepo\exam4\GIS_exam4\World_Countries_(Generalized)_8414823838130214587.gpkg' 
##   using driver `GPKG'
## Simple feature collection with 251 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -20037510 ymin: -30240970 xmax: 20037510 ymax: 18418390
## Projected CRS: WGS 84 / Pseudo-Mercator
head(worldmap)
## Simple feature collection with 6 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -19015950 ymin: -2039467 xmax: 8339582 ymax: 5260415
## Projected CRS: WGS 84 / Pseudo-Mercator
##          country iso    countryaff aff_iso                          SHAPE
## 1    Afghanistan  AF   Afghanistan      AF MULTIPOLYGON (((6821275 424...
## 2        Albania  AL       Albania      AL MULTIPOLYGON (((2178615 511...
## 3        Algeria  DZ       Algeria      DZ MULTIPOLYGON (((512443 4423...
## 4 American Samoa  AS United States      US MULTIPOLYGON (((-19007124 -...
## 5        Andorra  AD       Andorra      AD MULTIPOLYGON (((160949.7 52...
## 6         Angola  AO        Angola      AO MULTIPOLYGON (((2613349 -19...

Joining the data

Using Countrycode package, we match the ISO codes between our map and our data set, then we merge the files using left join. Finally we set the CRS, for this case we decided to use ESRI:54030, because the countries are represented closer to their actual size than the Mercator projection.

gii_map <- worldmap %>%
  mutate(iso= countrycode(iso, origin = "iso2c", destination = "iso3c")) %>%
  left_join(.,df_gii, by=c("iso" = "iso3")) %>%
  st_transform(., crs = 54030)
## Warning in CPL_crs_from_input(x): GDAL Message 1: EPSG:54030 is not a valid CRS
## code, but ESRI:54030 is. Assuming ESRI:54030 was meant

Plotting the Histogram

We set up a basic histogram to see the distribution of the values, also including the mean.

gghist <- ggplot(df_gii, 
                 aes(x=diff2019_10)) + 
  geom_histogram(color="black", 
                 fill="white",
                 bins=60)
  labs(title="Distribution of change in the GII (2010–2019)", 
       x="Variation of GII",
       y="Frequency")
## <ggplot2::labels> List of 3
##  $ x    : chr "Variation of GII"
##  $ y    : chr "Frequency"
##  $ title: chr "Distribution of change in the GII (2010–2019)"
# add a vertical line to the hisogram showing mean tempearture
gghist + geom_vline(aes(xintercept=mean(diff2019_10, 
                                        na.rm=TRUE)),
                    color="blue", 
                    linetype="dashed", 
                    size=1)+
  theme(plot.title = element_text(hjust = 0.5))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 41 rows containing non-finite outside the scale range
## (`stat_bin()`).

The histogram shows that the majority of countries, experienced an improvement in their inequality index. (positive values)

Plotting the Map

Plot a static map representing the Difference in Gender inequality Index, setting a scale fill gradient that represents the variation of GII: the color green for the countries that shown an improvement, while the yellow represents the countries that got worst.

ggplot(gii_map) +
  geom_sf(aes(fill = diff2019_10), color = "grey70", size = 0.15) +
  scale_fill_gradient2(
    name = "Variation of GII",
    low = "#FFD700",    # amarillo (bajos)
    mid = "white",      # 0
    high = "#18392B",   # verde (altos)
    midpoint = 0,
    limits=NULL,
    na.value = "grey90"
  ) +
  coord_sf(crs = "ESRI:54030", expand = FALSE) +
  labs(
    title = "Difference in Gender inequality index 2010 - 2019",
    caption = "Source: Human Development Report (UNDP)"
  ) +
  theme_test() 

Plotting a Dinamic Map

tmap_mode("view")
## ℹ tmap modes "plot" - "view"
## ℹ toggle with `tmap::ttm()`
tm_shape(gii_map) + 
  # add polygon layer
  tm_polygons(fill="diff2019_10",
              fill.scale= tm_scale_intervals (values="carto.blu_grn",
                                             style="jenks"),
              fill_alpha = 0.9,
          
              fill.legend = tm_legend(title = "Difference in inequality index", 
                                      size = 0.4))+
  tm_basemap(server = "OpenStreetMap") +
  tm_compass(type = "arrow", position = c("left", "bottom")) + 
  tm_scalebar(position = c("left", "bottom"))+
  tm_title("Difference in Gender inequality index 2010 - 2019", 
           size = 1,
           position = c("center", "top"))